package modulesAPI.v2.basics;

import javax.swing.JCheckBox;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import com.caterina.components.CPanel;
import com.caterina.resources.CModules;

import modulesAPI.v2.Module;
import modulesAPI.v2.ViewType;

public class ModCheckBox extends Module<Boolean>implements ChangeListener{
	/**
	 * Crea un nuovo modulo per l'inserimento/rappresentazione di un flag o booleano
	 * */
	public ModCheckBox(Module<?> ownerModule, Boolean content, String tag,String description, ViewType viewType) {
		super(ownerModule, content, tag, description, viewType);
		this.chBox=new JCheckBox();
		chBox.setSelected(this.getContent());
		this.chBox.addChangeListener(this);
	}
	@Override
	protected void beforeFireChange(Module<?> mod) {}
	@Override
	protected void afterFireChange(Module<?> mod) {}

	@Override
	protected CPanel getReadOnlyPanel(boolean isSelected) {
		return 	CModules.formatPanelForReadOnlyPairs(this.getTag(), this.getContent().toString());
	}
	@Override
	protected CPanel getWritablePanel(boolean isSelected) {
			return CModules.formatForPairs(this.getTag(), chBox);
	}
	@Override
	public void stateChanged(ChangeEvent e) {
		this.setContent(chBox.isSelected());
		fireModuleChanged(this);
	}
	@Override
	public CPanel getInListPanel(boolean isSelected) {
		return new CPanel();
	}
	@Override
	protected CPanel getOneLinePanel(boolean isSelected) {
		return this.getReadOnlyPanel(isSelected);
	}
	private JCheckBox chBox;
}
